/*
 * Created on 30.01.2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ro.qi.framework.sys.entities.components;

import ro.qi.framework.sys.entities.exception.ComponentException;

/**
 * @author Vlad Lepadatu
 *
 * This component should support values like  0/1, m/f, male/female, b/f, baiat/fata, barbat/femeie
 */
public class GenderComponent extends StringComponent {

	/**
	 * @see ro.qi.framework.entities.components.EntityComponent#verify(java.lang.Object)
	 */
	public void verify(Object _value) throws ComponentException {
		if( _value instanceof Integer ) {
			int intValue = ((Integer)_value).intValue();
			if( intValue == 0 || intValue == 1 )
				return;
		} else if( _value instanceof String ) {
			String str = (String)_value;
			if( str.equals("m") || str.equals("f") ||
				str.equals("0") || str.equals("1") ||
				str.equals("b") ||
				str.equals("male") || str.equals("female") ||
				str.equals("baiat") || str.equals("fata") ||
				str.equals("barbat") || str.equals("femeie") )
			return;
		}
		throw new ComponentException(this.getClass().getName() + ": [" + value.toString() + "] is not a Gender");
	}

	/**
	 * @see ro.qi.framework.entities.components.EntityComponent#setValue(java.lang.Object)
	 */
	public void setValue(Object _value) throws ComponentException {
		verify(_value);
		if( _value instanceof String ) {
			String str = (String)_value;
			if( str.equals("0") ||
				str.equals("m") ||
				str.equals("b") ||
				str.equals("male") ||
				str.equals("baiat") ||
				str.equals("barbat") ) {
				value = "m";
			} else {
				value = "f";
			}
		} else if( _value instanceof Integer ) {
			int intValue = ((Integer)_value).intValue();
			value = (intValue == 0)?"m":"f";
		}
	}

}
